package com.ld.security.shop.crawler.modules.re.crawler.fulinlin;

import com.ld.security.shop.crawler.modules.re.constant.CrawlerConstant;
import com.ld.security.shop.crawler.modules.re.crawler.BaseCrawler;
import com.ld.security.shop.crawler.modules.re.entity.ReDetails;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

@Component
public class FulinlinReDetailsCrawler extends BaseCrawler<ReDetails> {

    public FulinlinReDetailsCrawler() {
        super( CrawlerConstant.projectCode.java1234);
    }


    @Override
    public ReDetails dataCrawler(String url) {


        ReDetails re =  super.dataCrawler(url);
        Document document =  this.parse(re.getContent());
        Element content = document.select("#posts .post-body").first();
        re.setContent(content.html());

       Elements as =  document.select(".post-nav a");
        for (Element a : as) {
            Element left = a.select(".fa-chevron-left").first();
            Element right = a.select(".fa-chevron-right").first();

            if(left != null){
                re.setPreUrl(a.attr("href"));
            }
            if(right != null){
                re.setNextUrl(a.attr("href"));
            }
        }
        return  re;
    }
}

